//
//  ViewController.m
//  Exercise
//
//  Created by zhouxiaobo on 15/11/6.
//  Copyright © 2015年 mapath. All rights reserved.
//

#import "ViewController.h"


@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(10, 30, 300, 528)];
    view1.backgroundColor = [UIColor greenColor];
    
    [self.view addSubview:view1];
    
    //获取当前系统的版本
    NSLog(@"当前系统的版本：%@",[UIDevice currentDevice].systemVersion);
    
    //打印手机的分辨率
    NSLog(@"w:%f,h:%f",[[UIScreen mainScreen] bounds].size.width,[[UIScreen mainScreen] bounds].size.height);
    
    //bounds和frame的区别
    NSLog(@"frame - w:%f h:%f x:%f y:%f",view1.frame.size.width,view1.frame.size.height,view1.frame.origin.x,view1.frame.origin.y);
    
    NSLog(@"bounds - w:%f h:%f x:%f y:%f",view1.bounds.size.width,view1.bounds.size.height,view1.bounds.origin.x,view1.bounds.origin.y);  //bounds就是边框的大小，x,y永远为0
    
    //中心点
    NSLog(@"center - x:%f y:%f", view1.center.x, view1.center.y);
    
    //获取父视图
    UIView *superView = [view1 superview];
    superView.backgroundColor = [UIColor whiteColor];
    
    //添加2个子视图
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 30, 80)];
    view2.tag = 2;
    
    UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(20, 60, 60, 30)];
    view3.tag = 3;
    
    [view1 addSubview:view2];
    [view1 addSubview:view3];
    
    //获取子视图
    NSArray *subViews = [view1 subviews];
    for (UIView *view in subViews) {
        if(view.tag == 2){
            view.backgroundColor = [UIColor orangeColor];
        }
    }
    
    //直接获得子视图
    UIView *tag3View = [view1 viewWithTag:3];
    tag3View.backgroundColor = [UIColor purpleColor];
    
    //视图的层次结构
    //1.先加入的视图在后面
    //2.子视图跟随父视图做层级变化
    
    //交换图层
    [view1 exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    
    //插入图层
    UIView *view4 = [[UIView alloc]initWithFrame:CGRectMake(20, 80, 300, 30)];
    view4.backgroundColor = [UIColor blackColor];
    
    //[view1 insertSubview:view4 atIndex:3];
    
    [view1 insertSubview:view4 aboveSubview:view2];
    
    //直接插入最顶层
    [view1 bringSubviewToFront:view3];  //将view1里的view3放到view1里的第一层
    
    //直接放入最底层
    [view1 sendSubviewToBack:view2]; //将view1里的view2放到view1里的第后一层
    
    //自适应
    UIView *view5 = [[UIView alloc]init];
    view5.tag = 1001;
    view5.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/2 - 25, 300, 50, 50);
    view5.backgroundColor = [UIColor redColor];
    
    //设置子视图自适应
    view5.autoresizesSubviews = YES;
    [self.view addSubview:view5];
    
    UIView *view6 = [[UIView alloc]init];
    view6.frame = CGRectMake(10, 10, 30, 30);
    view6.backgroundColor = [UIColor yellowColor];
    view6.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin| UIViewAutoresizingFlexibleRightMargin;
    [view5 addSubview:view6];
    
    UIButton *button = [[UIButton alloc]init];
    button.frame = CGRectMake(20, 400, 100, 30);
    button.backgroundColor = [UIColor blueColor];
    [button setTitle:@"Click me" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button];
    
    
    UILabel *lable = [[UILabel alloc]init];
    lable.frame = CGRectMake(60, 200, 230, 300);
    lable.text = @"作为一名资深的java开发人员，长期从事企业级程序工作，习惯了上班打工的节奏，到了一定的年龄就会想到创业，开自己的公司，这样也算是真正有了自己的事业。可是真到了创业的时候又有多少人知道该怎么做呢，发展路线该怎么走，如何能做出正确的选择？创业不仅要我们辛勤的做基础工作，而且要到处拉投资，如果没有足够的资金支持，一切都是空谈，对此很多人都会陷入迷茫，感觉上很难熬，但又抑制不住心中对成功的渴望，路要一步一步的去探索，这里分享一个创业学习的平台";
    lable.backgroundColor = [UIColor colorWithRed:0.8 green:0.2 blue:0.3 alpha:0.5];
    lable.textColor = [UIColor whiteColor];
    
    //设置字体大小
    lable.font = [UIFont systemFontOfSize:25];
    
    //设置粗体，斜体，会覆盖上面的设置
    lable.font = [UIFont boldSystemFontOfSize:25];
    lable.font = [UIFont italicSystemFontOfSize:25];
    
    //设置字体
    for (NSString *fontName in [UIFont familyNames]) {
        NSLog(@"%@",fontName);
    }
    lable.font = [UIFont fontWithName:@"Kohinoor Devanagari" size:12];
    
    //设置label的阴影
    //lable.shadowColor = [UIColor grayColor];
    //lable.shadowOffset = CGSizeMake(2, 2);
    
    //设置换行模式（英文有效）
    lable.lineBreakMode = NSLineBreakByCharWrapping;
    //设置换行行数 (0或－1就不控制行数)
    lable.numberOfLines = 30;
    
    //根据字符串大小计算label的大小
    CGSize size = [lable.text sizeWithFont:lable.font constrainedToSize:CGSizeMake(230, 10000) lineBreakMode:NSLineBreakByCharWrapping]; //constrainedToSize 是定义一个限制大小，宽度就设置成原来frame的宽度
    lable.frame = CGRectMake(lable.frame.origin.x, lable.frame.origin.y, lable.frame.size.width, size.height);
    
    
    [self.view addSubview:lable];
    
    //获取工程的路径
    NSString *path = [[NSBundle mainBundle] resourcePath];
    NSLog(@"%@",path);
    
    //这2种记载方式的不同，前一种不会加载到内存里，后一种会加载到内存里
    //UIImage *image = [[UIImage alloc]initWithContentsOfFile:[NSString stringWithFormat:@"%@/1",path]];
    UIImage *image1 = [UIImage imageNamed:@"1"];
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 180, 300, 350)];      //图片的显示大小跟着UIImageView的frame
    imageView.image = image1;
    imageView.backgroundColor = [UIColor yellowColor];
    
    //图片内容模式设置
    //UIViewContentModeScaleAspectFill - 拉伸不改变比例，充满最大的一边
    //UIViewContentModeScaleAspectFit - 拉伸不改变比例，充满最小的一边
    //UIViewContentModeScaleToFill - 拉伸充满整个载体
    imageView.contentMode = UIViewContentModeScaleToFill;
    
    
    
    
    [self.view addSubview:imageView];
    
}

- (void)btnClick{
    UIView *temView = [self.view viewWithTag:1001];
    temView.frame = CGRectMake(temView.frame.origin.x-5, temView.frame.origin.y-5, temView.frame.size.width+10, temView.frame.size.height+10);
}

- (void)openModel{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
